/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package agenda.contato;

import agenda.contato.DAL.ContatoDAL;
import framework.agendaFactory.BasicAgendaFactory;
import framework.agendaFactory.lib.InternalFrame;
import framework.groups.GroupStrategy;
import java.awt.event.ActionListener;
import javax.swing.JFormattedTextField;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTable;
import javax.swing.event.InternalFrameEvent;
import javax.swing.text.MaskFormatter;

/**
 *
 * @author Sergio Carlos Peres
 */
public class ContatoFactory extends BasicAgendaFactory{

    public int codigo;
    private javax.swing.JTable tabela = new javax.swing.JTable();
    private javax.swing.JTextField txtNome;
    private javax.swing.JTextField txtEmail;
    private javax.swing.JTextField txtEndereco;
    private javax.swing.JTextField txtNumero;
    private javax.swing.JTextField txtPaiz;
    private javax.swing.JTextField txtBairro;
    private javax.swing.JTextField txtEstado;
    private javax.swing.JTextField txtCidade;
    private javax.swing.JFormattedTextField txtFoneResidencial;
    private javax.swing.JFormattedTextField txtFoneComercial;
    private javax.swing.JFormattedTextField txtFoneCelular;
    private javax.swing.JFormattedTextField txtFoneOutro;
    private javax.swing.JFormattedTextField txtDataNascimento;
    MaskFormatter foneResidencial, foneComercial, foneCelular, foneOutro, data;
    
    @Override
    public void jInternalFrameOpened(InternalFrameEvent evt) {
        this.controle = true;
        preencheTabela("SELECT * FROM contato");
        
    }

    @Override
    public void preencheTabela(String sql) {
        tabela.getColumnModel().getColumn(0).setPreferredWidth(200);
        tabela.getColumnModel().getColumn(1).setPreferredWidth(200);
        tabela.getColumnModel().getColumn(2).setPreferredWidth(150);
        tabela.getColumnModel().getColumn(3).setPreferredWidth(150);
        tabela.getColumnModel().getColumn(4).setPreferredWidth(150);
        
        javax.swing.table.DefaultTableModel modelo = (javax.swing.table.DefaultTableModel)tabela.getModel();
        modelo.setNumRows(0);
        
        framework.dal.Conexao conexao = new framework.dal.Conexao();
        conexao.conecta();
        try {
            conexao.executeSelect(sql);
            while (conexao.resultset.next()) {
                // idcontato, nome, email, endereco, numero, cidade, estado, paiz, residencial, comercial, celular, outro, data
                modelo.addRow(new Object [] {conexao.resultset.getString("nome"),
                    conexao.resultset.getString("email"), conexao.resultset.getString("residencial"),
                    conexao.resultset.getString("celular"),framework.utilitarios.Data.retornaStirng(conexao.resultset.getDate("data"))
                });
            }
        } catch (java.sql.SQLException ex) {
            System.out.println("Pau...\nColocar mensagem de erro em: preencheTabela() de CompromissoFectory");
        }
        conexao.desconecta();
    }

    @Override
    public void ativaCamposAdicionar(boolean b) {
        txtNome.setEnabled(b);
        txtEmail.setEnabled(b);
        txtEndereco.setEnabled(b);
        txtNumero.setEnabled(b);
        txtBairro.setEnabled(b);
        txtCidade.setEnabled(b);
        txtEstado.setEnabled(b);
        txtPaiz.setEnabled(b);
        txtFoneResidencial.setEnabled(b);
        txtFoneComercial.setEnabled(b);
        txtFoneCelular.setEnabled(b);
        txtFoneOutro.setEnabled(b);
        txtDataNascimento.setEnabled(b);
        if (b)
            txtNome.requestFocus();
    }

    @Override
    public void limpaAdicionar() {
        codigo = 0;
        txtNome.setText("");
        txtEmail.setText("");
        txtEndereco.setText("");
        txtNumero.setText("");
        txtBairro.setText("");
        txtCidade.setText("");
        txtEstado.setText("");
        txtPaiz.setText("");
        txtFoneResidencial.setText("");
        txtFoneComercial.setText("");
        txtFoneCelular.setText("");
        txtFoneOutro.setText("");
        txtDataNascimento.setText("");
    }

    @Override
    public Object getTela() {
        return new Contato(codigo, txtNome.getText(), txtEmail.getText(), 
                new Endereco(txtEndereco.getText(), Integer.parseInt(txtNumero.getText()), 
                        txtBairro.getText(), txtCidade.getText(), txtEstado.getText(), txtPaiz.getText()), 
                new Telefone(txtFoneResidencial.getText(), txtFoneComercial.getText(), 
                        txtFoneCelular.getText(), txtFoneOutro.getText()),
                framework.utilitarios.Data.retornaData(txtDataNascimento.getText()));
    }

    @Override
    public void setTela(Object o) {
        Contato contato = (Contato) o;
        codigo = contato.getCodigo();
        txtNome.setText(contato.getNome());
        txtEmail.setText(contato.getEmail());
        txtEndereco.setText(contato.getEndereco().getLogradouro());
        txtNumero.setText(contato.getEndereco().getNumeno() + "");
        txtBairro.setText(contato.getEndereco().getBairro());
        txtCidade.setText(contato.getEndereco().getCidade());
        txtEstado.setText(contato.getEndereco().getEstado());
        txtPaiz.setText(contato.getEndereco().getPaiz());
        txtFoneResidencial.setText(contato.getTelefone().getResidencial());
        txtFoneComercial.setText(contato.getTelefone().getComercial());
        txtFoneCelular.setText(contato.getTelefone().getCelular());
        txtFoneOutro.setText(contato.getTelefone().getOutro());
        txtDataNascimento.setText(framework.utilitarios.Data.retornaStirng(contato.getData()));
    }

    @Override
    public ActionListener criarActionListener(InternalFrame internalFrame) {
        ContatoButtonListener listener = new ContatoButtonListener(internalFrame);
        return listener;
    }

    @Override
    public JPanel[] criaPanel(ActionListener listener) {
        javax.swing.JPanel[] panel = new javax.swing.JPanel[2];

        panel[0] = new javax.swing.JPanel();
        panel[1] = new javax.swing.JPanel();
        
        //<editor-fold defaultstate="collapsed" desc=" Cria o panel para a aba de Listagem ">
        /**
         * Cria o panel da aba de listagem
         */
        javax.swing.JScrollPane jScrollPane1 = new javax.swing.JScrollPane();
        javax.swing.JLabel jLabel15 = new javax.swing.JLabel();
        javax.swing.JSeparator jSeparator8 = new javax.swing.JSeparator();
        
        tabela.setAutoCreateRowSorter(true);
        tabela.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        tabela.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null},
                {null, null, null, null, null}
            },
            new String [] {
                "Nome", "E-mail", "Telefone", "Calular", "Data de Nascimento"
            }
        ) {
            boolean[] canEdit = new boolean [] {
                false, false, false, false, false
            };

            public boolean isCellEditable(int rowIndex, int columnIndex) {
                return canEdit [columnIndex];
            }
        });
        tabela.setMaximumSize(new java.awt.Dimension(2147483647, 2147483647));
        jScrollPane1.setViewportView(tabela);
        tabela.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                tabelaMouseClicked(evt);
            }
        });
        tabela.getAccessibleContext().setAccessibleName("");
        tabela.getAccessibleContext().setAccessibleDescription("");
        
        jLabel15.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel15.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel15.setText("Clique para ver todas as infomações de um contato.");
        
        javax.swing.GroupLayout panelContatosLayout = new javax.swing.GroupLayout(panel[0]);
        panel[0].setLayout(panelContatosLayout);
        panelContatosLayout.setHorizontalGroup(
            panelContatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(panelContatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(panelContatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jSeparator8)
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 649, Short.MAX_VALUE)
                    .addComponent(jLabel15, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        panelContatosLayout.setVerticalGroup(
            panelContatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelContatosLayout.createSequentialGroup()
                .addGap(12, 12, 12)
                .addComponent(jLabel15)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator8, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 385, Short.MAX_VALUE)
                .addContainerGap())
        );
        //</editor-fold>
        
        //<editor-fold defaultstate="collapsed" desc=" Cria o panel para a aba de Cadastro ">
        /**
         * Cria a aba de cadastro
         */
        javax.swing.JLabel jLabel1 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel2 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel3 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel4 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel5 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel6 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel7 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel8 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel9 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel10 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel11 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel12 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel13 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel14 = new javax.swing.JLabel();
        javax.swing.JLabel jLabel16 = new javax.swing.JLabel();
        javax.swing.JSeparator jSeparator1 = new javax.swing.JSeparator();
        javax.swing.JSeparator jSeparator2 = new javax.swing.JSeparator();
        javax.swing.JSeparator jSeparator3 = new javax.swing.JSeparator();
        javax.swing.JSeparator jSeparator5 = new javax.swing.JSeparator();
        javax.swing.JPanel jPanel = new javax.swing.JPanel();
        
        txtNome = new javax.swing.JTextField();
        txtEmail = new javax.swing.JTextField();
        txtEndereco = new javax.swing.JTextField();
        txtNumero = new javax.swing.JTextField();
        txtPaiz = new javax.swing.JTextField();
        txtBairro = new javax.swing.JTextField();
        txtEstado = new javax.swing.JTextField();
        txtCidade = new javax.swing.JTextField();
        //<editor-fold defaultstate="collapsed" desc=" Telefones ">
        try {
            
            foneResidencial = new MaskFormatter("(##) ####-####");
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Não foi possivel setar a mascara.\n\n\tErro: " + erro);
        }
        txtFoneResidencial = new JFormattedTextField(foneResidencial);
        try {
            foneComercial = new MaskFormatter("(##) ####-####");
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Não foi possivel setar a mascara.\n\n\tErro: " + erro);
        }
        txtFoneComercial = new JFormattedTextField(foneComercial);
        try {
            foneCelular = new MaskFormatter("(##) ####-####");
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Não foi possivel setar a mascara.\n\n\tErro: " + erro);
        }
        txtFoneCelular = new JFormattedTextField(foneCelular);
        try {
            foneOutro = new MaskFormatter("(##) ####-####");
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Não foi possivel setar a mascara.\n\n\tErro: " + erro);
        }
        txtFoneOutro = new JFormattedTextField(foneOutro);
        //</editor-fold>
        try {
            data = new MaskFormatter("##/##/####");
        } catch (Exception erro) {
            JOptionPane.showMessageDialog(null, "Não foi possivel setar a mascara.\n\n\tErro: " + erro);
        }
        txtDataNascimento = new JFormattedTextField(data);
        
        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel10.setText("Residencial: ");
        
        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel11.setText("Celular: ");
        
        jLabel9.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel9.setText("Telefone: ");
        
        txtNome.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtNome.setToolTipText("Nome");
        
        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel2.setText("Nome: ");
        
        txtFoneOutro.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFoneOutro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        
        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel1.setText("Adicionar um novo contato a agenda.");
        
        txtFoneCelular.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFoneCelular.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        
        txtFoneComercial.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFoneComercial.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        
        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel4.setText("Endereço: ");
        
        txtFoneResidencial.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtFoneResidencial.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        
        txtEmail.setToolTipText("E-mail");
        txtEmail.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        
        jLabel13.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel13.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel13.setText("Outro: ");
        
        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel3.setText("Email:");
        
        jLabel12.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel12.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
        jLabel12.setText("Comercial: ");
        
        txtEndereco.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtEndereco.setToolTipText("Endereço");
        
        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel5.setText("Nº: ");
        
        txtNumero.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtNumero.setToolTipText("Número");
        
        jLabel14.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel14.setText("Data de Nascimento: ");
        
        txtDataNascimento.setHorizontalAlignment(javax.swing.JTextField.CENTER);
        txtDataNascimento.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        
        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel8.setText("Paiz: ");
        
        txtPaiz.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtPaiz.setToolTipText("Paiz");
        
        txtBairro.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtBairro.setToolTipText("Cidade");
        
        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel6.setText("Bairro: ");
        
        txtEstado.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtEstado.setToolTipText("Estado");
        
        jLabel7.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel7.setText("Estado: ");
        
        jLabel16.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        jLabel16.setText("Cidade: ");
        
        txtCidade.setFont(new java.awt.Font("Tahoma", 1, 12)); // NOI18N
        txtCidade.setToolTipText("Cidade");
        
        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel);
        jPanel.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jSeparator2)
                .addComponent(jSeparator1)
                .addComponent(jSeparator3)
                .addComponent(jSeparator5)
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel3)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(jLabel9)
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jLabel10, javax.swing.GroupLayout.DEFAULT_SIZE, 100, Short.MAX_VALUE)
                .addComponent(jLabel12, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(txtFoneComercial, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(txtFoneResidencial, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                .addComponent(jLabel11, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                .addComponent(jLabel13, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addComponent(txtFoneCelular, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(txtFoneOutro, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel14)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, 140, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 541, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel6)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, 220, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel16)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtCidade))
                .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel4)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, 351, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addComponent(jLabel5)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(0, 86, Short.MAX_VALUE)))
                .addContainerGap())
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel7)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtEstado)
                .addGap(18, 18, 18)
                .addComponent(jLabel8)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(txtPaiz, javax.swing.GroupLayout.PREFERRED_SIZE, 192, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(142, 142, 142))))
                );
        jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel2)
                .addComponent(txtNome, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel3)
                .addComponent(txtEmail, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel4)
                .addComponent(txtEndereco, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addComponent(jLabel5)
                .addComponent(txtNumero, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel16)
                .addComponent(txtCidade, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel6)
                .addComponent(txtBairro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel7)
                .addComponent(txtEstado, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel8)
                .addComponent(txtPaiz, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(13, 13, 13)
                .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jLabel9)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel10)
                .addComponent(txtFoneResidencial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel12)
                .addComponent(txtFoneComercial, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel11)
                .addComponent(txtFoneCelular, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel13)
                .addComponent(txtFoneOutro, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addGap(18, 18, 18)
                .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(jLabel14)
                .addComponent(txtDataNascimento, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(85, Short.MAX_VALUE))
                );
        
        javax.swing.GroupLayout panelAdicionarLayout = new javax.swing.GroupLayout(panel[1]);
        panel[1].setLayout(panelAdicionarLayout);
        panelAdicionarLayout.setHorizontalGroup(
                panelAdicionarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, panelAdicionarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
                );
        panelAdicionarLayout.setVerticalGroup(
                panelAdicionarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(panelAdicionarLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addContainerGap())
                );
        //</editor-fold>

        return panel;
    }

    @Override
    public JTable getTabelaLista() {
        return tabela;
    }
    
    public void tabelaMouseClicked(java.awt.event.MouseEvent evt) {
        if (evt.getClickCount() == 1){ 
            int linha;
            linha = tabela.getSelectedRow();
            
            Contato c = new Contato();
            c.setNome(tabela.getValueAt(linha, 0).toString());
            c.setEmail(tabela.getValueAt(linha, 1).toString());
            
            limpaAdicionar();
            
            this.setTela(new ContatoDAL().buscaAlterar(c));
            ativaCamposAdicionar(false);
        }
    }

    @Override
    public String getSQL() {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }

    @Override
    public void setSQL(String sql) { }

    @Override
    public GroupStrategy getStrategy() { return null; }
    
}
